package tests;

import java.io.File;

import org.gstreamer.Gst;
import org.junit.Assert;
import org.junit.Before;
import org.junit.After;
import org.junit.Test;
import video.Metadata;

/**
 * 
 * @author Heitor Meira de Melo
 * 
 */
public class MetadataTest {
	private Metadata metadata;
	private String file;

	@Before
	public void setUp() throws Exception {
		file = "Videos/Samples/bailey.flv";
		Gst.init();
		metadata = new Metadata(file);
	}

	@After
	public void clear() throws Exception {
		file = null;
		metadata = null;
		Gst.quit();

	}

	@Test
	public void testInesistentFile() {
		metadata.setInputFile(new File("Pagodeiro_Macho.flv"));
		Assert.assertFalse(metadata.isPlayable());
	}

	@Test
	public void testFileSize() {
		Assert.assertEquals(710423L, metadata.getFileSize());
	}

	@Test
	public void testWidth() {
		Assert.assertEquals("720.0", metadata.getWidth());
	}

	@Test
	public void testHeight() {
		Assert.assertEquals("480.0", metadata.getHeight());
	}

	@Test
	public void testGetDuration() {
		metadata = new Metadata("Videos/Samples/stinsonAwesome.flv");
		Assert.assertEquals(58.2, metadata.getDuration(), 0.01);
	}

	@Test
	public void testGetframeRate() {
		Assert.assertEquals("18.0", metadata.getFrameRate());
	}

	@Test
	public void testGetLocator() {
		Assert.assertEquals(new File("Videos/Samples/bailey.flv")
				.getAbsolutePath(), metadata.getLocator());
	}

	@Test
	public void testGetSampleRate() {
		// Some video has not some metadata tags... So it returns null. Like
		// this;
		Assert.assertEquals(null, metadata.getSampleRate());
	}

	@Test
	public void testGetVideoContainer() {
		Assert.assertEquals("Sorenson Video", metadata.getVideoContainer());
	}

	@Test
	public void testGetVideoName() {
		Assert.assertEquals("bailey.flv", metadata.getVideoName());
	}

	@Test
	public void testIsPlayable() {
		// Some video has duration 0, this videos are no playable
		Assert.assertFalse(metadata.isPlayable());
	}

	@Test
	public void testIsPlayabledf() {
		Assert.assertEquals("bailey.flv", metadata.getVideoName());
		metadata.setInputFile(new File("Videos/Samples/stinsonAwesome.flv"));
		Assert.assertEquals("stinsonAwesome.flv", metadata.getVideoName());
	}
}
